<?php 
namespace app\agent\controller;

use app\common\model\user\Users;
use app\common\model\coin\CoinUser;
use app\common\model\coin\CoinList;

class User extends Base
{
	public function index()
	{
		if($this->request ->isAjax()){
			$data = $this->request->post('');
			$where = ['act_id' => $this->agent_id];
			if(!empty($data['mobile']))$where['mobile'] = $data['mobile'];
			if(!empty($data['tjuser']))$where['tjuser'] = $data['tjuser'];
			if(!empty($data['start_time']) && !empty($data['end_time'])) {
				$start_time = strtotime($data['start_time']);
				$end_time = strtotime($data['end_time']);
				if($start_time > $end_time)return $this->error('时间不正确');
				$where['create_time'] = ['between',[$start_time,$end_time]];
			}
			$list = Users::where($where)->order('id desc')->paginate()->toArray();
			foreach ($list['data'] as &$rows) {
				$rows['tj_mobile'] = Users::where(['no' => $rows['tjuser']])->value('mobile');
			}
			return $this->success($list);
		}
		return view();
	}
	public function userInfo()
	{
		$id = $this->request->param('id');
		//获取会员账户余额
		$user_coin = CoinUser::where(['user_id' => $id,'state' => 1])->select();
		foreach ($user_coin as &$rows) {
			$rows['coin_info'] = CoinList::get($rows['coin_id']);
		}
		//获取用户信息
		$user_info = Users::get($id);
		$user_info->tj_mobile = Users::where(['no' => $user_info->tjuser])->value('mobile');
		$this->assign('user_coin',$user_coin);
		$this->assign('user_info',$user_info);
		return view();
	}
}